#!/usr/bin/python
# -*-  coding: utf-8  -*-

from django import forms
from django.forms.widgets import RadioSelect, Textarea, DateInput
from crmv2.survey.models import Survey

def CreateFormForSurveyTemplate(template):
    form = forms.Form()
    for question in template.surveyquestion_set.all():
        if question.type == 'T':
            form.fields[str(question.index)] = forms.CharField(label = ('%d. %s' % (question.index, question.label)))
        elif question.type == 'S':
            field = forms.ChoiceField(label = ('%d. %s' % (question.index, question.label)))
            field.choices = [(c.index, c.label) for c in question.surveychoice_set.all()]
            form.fields[str(question.index)] = field
        elif question.type == 'R':
            field = forms.ChoiceField(label = ('%d. %s' % (question.index, question.label)), widget = RadioSelect)
            field.choices = [(c.index, c.label) for c in question.surveychoice_set.all()]
            form.fields[str(question.index)] = field
        else:
            field = forms.CharField(label = ('%d. %s' % (question.index, question.label)), widget = Textarea)
            form.fields[str(question.index)] = field

    return form

class SurveyForm(forms.ModelForm):
    notify_1 = forms.DateField(label = '1st Notify At', required = False, widget = DateInput)
    notify_2 = forms.DateField(label = '2nd Notify At', required = False, widget = DateInput)
    notify_3 = forms.DateField(label = '3rd Notify At', required = False, widget = DateInput)
    class Meta:
        model = Survey
        fields = ['title', 'owner', 'description', 'template']


